package com.usvisatrack.core.factories;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.usvisatrack.core.common.Factory;
import com.usvisatrack.core.dao.model.USEmbassy;
import com.usvisatrack.core.dao.model.Visa;
import com.usvisatrack.core.dao.model.VisaClass;

/**
 * Item Data Factory
 * 
 * @author YuCheng Hu
 *
 */
public class USFactory extends Factory {
	private static Logger logger = LoggerFactory.getLogger(USFactory.class);

	private static final int LISTING_PAGE_SIZE = 20;
	public static final int DEFAULT_AUTH_EXPIRATION = 10;

	/**
	 * get USEmbassy
	 * 
	 * @param country
	 * @param city
	 * @return
	 */
	public static USEmbassy searchUSEmbassy(String country, String city) {
		logger.debug("Search USEmbassy - [{}]/[{}]", country, city);
		try {
			Factory.beginTransaction();
			Criteria criteria = Factory.createCriteria(USEmbassy.class);
			criteria.add(Restrictions.ilike("country", "%" + country + "%"));
			criteria.add(Restrictions.ilike("city", "%" + city + "%"));
			criteria.setMaxResults(1);
			return (USEmbassy) criteria.uniqueResult();
		} catch (Exception ex) {
			logger.error("Search USEmbassy data error", ex);
		} finally {
			Factory.commitTransaction();
		}

		return null;
	}

}